import { compileToFunction } from './compiler/index.js'
import { initState } from './state'

export default function initMixin(Vue) {
  // 初始化配置
  Vue.prototype._init = function (options) {
    const vm = this
    // 在vue中通过this实例访问到$options 访问到了所有配置
    vm.$options = options
    initState(vm)
    if (vm.$options.el) {
      vm.$mount(vm.$options.el)
    }
  }
  Vue.prototype.$mount = function (el) {
    const vm = this
    const options = vm.$options
    el = document.querySelector(el)
    if (!options.render) {
      let template = options.template
      if (!template && el) {
        template = el.outerHTML
        // console.log(template)
        const render = compileToFunction(template)
        console.log(render())
      }
    }
  }
}
